﻿using Citi.HeadCount.Domain.Repository;
using NHibernate.Mapping.ByCode;

namespace Citi.HeadCount.Domain.Mapping
{
    public class RuleResultMap : EntityMapping<RuleResult>
    {
        public RuleResultMap()
        {
            Property(x => x.Active, m => { m.NotNullable(true); });
            Property(x => x.Name, m => { m.NotNullable(true); m.Length(50); });
            Property(x => x.Exception, m => { m.NotNullable(true); });

            Bag(x => x.Rules, c =>
            {
                c.Key(k =>
                {
                    k.NotNullable(false);
                    k.Column("RuleResultId");
                });
                c.Cascade(Cascade.None);
                c.Table("Rule");
            }, cr => cr.OneToMany(om => om.Class(typeof(Rule))));

            Bag(x => x.TypeRuleResults, c =>
            {
                c.Key(k =>
                {
                    k.NotNullable(false);
                    k.Column("RuleResultId");
                });
                c.Cascade(Cascade.None);
                c.Table("TypeRuleResult");
            }, cr => cr.OneToMany(om => om.Class(typeof(TypeRuleResult))));
        }
    }
}
